<?php

declare(strict_types=1);

namespace app\model\system;

use owns\interface\OwnsModelInteface;

class DictDataModel extends OwnsModelInteface
{
    protected $name = 'system_dict_data';

    protected $field = [];

    /**
     * 查询条件
     * @param object $query
     * @param array $param
     */
    public function scopeCustom(object $query, array $param)
    {
        // 字典类型ID
        if($typeId = $param['type_id'] ?? '') {
            $query->where('type_id', $typeId);
        }
        // 字典标签
        if($label = $param['label'] ?? '') {
            $query->whereLike('label', trim($label) . '%');
        }
        // 字典值
        if($value = $param['value'] ?? '') {
            $query->whereLike('value', trim($value) . '%');
        }
        // 字典标示
        if($code = $param['code'] ?? '') {
            $query->whereLike('code', trim($code) . '%');
        }
    }
}
